﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class menuControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);

            MPRepeater bMPRepeater = (MPRepeater)FindControl("MPRepeaterList");
            bMPRepeater.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(bMPRepeater_ItemDataBound);

            List<EluZSProvider.Menu> menu = _EluZSDataProvider.GetMenuTitle();//方法
            bMPRepeater.DataSource = menu;
            bMPRepeater.DataBind();

        }
        protected void bMPRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            EluZSProvider.Menu dr = (EluZSProvider.Menu)e.Item.DataItem;
            Literal showbmenu = (Literal)e.Item.FindControl("showbmenu");
            int itemindex = (e.Item.ItemIndex + 1);
            MPRepeater sMPRepeater = (MPRepeater)e.Item.FindControl("SMPRepeaterList");

            List<EluZSProvider.Menu> menucon = _EluZSDataProvider.GetMenuContent(dr.Id);
            sMPRepeater.DataSource = menucon;
            sMPRepeater.DataBind();
        }


        /// <summary>
        /// 省略字符
        /// </summary>
        /// <returns></returns>
        public static string TranString(object str, int length)
        {
            if (str != null)
            {
                if (!string.IsNullOrEmpty(str.ToString()))
                {
                    if (str.ToString().Length > length)
                    {
                        return "<span title='" + str.ToString() + "'>" + str.ToString().Substring(0, length) + "..." + "</span>";
                    }
                    return str.ToString();
                }
            }
            return "";
        }
    }
}


